package ludichat.cobbreeding.forge

import com.cobblemon.mod.common.NetworkManager
import com.cobblemon.mod.common.api.net.NetworkPacket
import com.cobblemon.mod.neoforge.net.NeoForgePacketInfo
import ludichat.cobbreeding.Cobbreeding
import net.minecraft.client.Minecraft
import net.minecraft.server.level.ServerPlayer
import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent
import net.neoforged.neoforge.network.registration.HandlerThread

object CobbreedingNeoforgeNetworkManager: NetworkManager {
    const val PROTOCOL_VERSION = "1.0.0"

    fun registerMessages(event: RegisterPayloadHandlersEvent) {
        val registrar = event.registrar(Cobbreeding.MOD_ID).versioned(PROTOCOL_VERSION)
        //val netRegistrar = event.registrar(Cobbreeding.MOD_ID).versioned(PROTOCOL_VERSION).executesOn(HandlerThread.NETWORK)

        NeoForgePacketInfo(Cobbreeding.INCUBATOR_PACKET_INFO).registerToClient(registrar)
    }

    override fun sendPacketToPlayer(player: ServerPlayer, packet: NetworkPacket<*>) {
        player.connection.send(packet)
    }

    override fun sendToServer(packet: NetworkPacket<*>) {
        Minecraft.getInstance().connection?.send(packet)
    }
}